package View;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Controller.Sistema;
import Model.Tipo;
import Model.TipoView2;
import Persistencia.AdministradorPersistenciaTipo;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AdmTipo extends javax.swing.JFrame {
	private static String titulo = "Menu Tipos";
	private JLabel jLabel1;
	private JComboBox jComboBox1;
	private JPanel jPanel1;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JTextField KmExcedente;
	private JButton jButton1;
	private JLabel jLabel5;
	private JLabel jLabel6;
	private JTextField costotexto;
	private JTextField jTextField1;
	private JLabel jLabel2;
	TipoView2 t;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AdmTipo inst = new AdmTipo();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AdmTipo() {
		super(titulo);
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Seleccione Tipo");
				jLabel1.setBounds(47, 43, 99, 24);
			}
			{
				ComboBoxModel jComboBox1Model = 
						new DefaultComboBoxModel(
								new String[] { " ","CPT","ECO", "SED","VAN" });
				jComboBox1 = new JComboBox();
				getContentPane().add(jComboBox1);
				jComboBox1.setModel(jComboBox1Model);
				jComboBox1.setBounds(195, 44, 84, 23);
				jComboBox1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jComboBox1.actionPerformed, event="+evt);
					    t=Sistema.getSistema().BuscarTipo((String)jComboBox1.getSelectedItem());
						KmExcedente.setText(String.valueOf(t.getKmexcedente()));
					    costotexto.setText(String.valueOf(t.getCostoxdia()));
					    jTextField1.setText(t.getTipo());
					    jPanel1.setVisible(true);
					}
				});
			}
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1);
				jPanel1.setBounds(59, 101, 257, 111);
				jPanel1.setLayout(null);
				jPanel1.setVisible(false);
				{
					jLabel2 = new JLabel();
					jPanel1.add(jLabel2);
					jLabel2.setText("Tipo");
					jLabel2.setBounds(12, 12, 24, 16);
				}
				{
					jLabel3 = new JLabel();
					jPanel1.add(jLabel3);
					jLabel3.setText("CostoXDia");
					jLabel3.setBounds(12, 40, 55, 16);
				}
				{
					jLabel4 = new JLabel();
					jPanel1.add(jLabel4);
					jLabel4.setText("KmExcedente");
					jLabel4.setBounds(12, 74, 78, 16);
				}
				{
					jTextField1 = new JTextField();
					jPanel1.add(jTextField1);
					jTextField1.setBounds(126, 9, 91, 23);
				}
				{
					costotexto = new JTextField();
					jPanel1.add(costotexto);
					costotexto.setBounds(146, 37, 56, 23);
				}
				{
					KmExcedente = new JTextField();
					jPanel1.add(KmExcedente);
					KmExcedente.setBounds(146, 71, 56, 23);
				}
				{
					jLabel5 = new JLabel();
					jPanel1.add(jLabel5);
					jLabel5.setText("$");
					jLabel5.setBounds(205, 40, 12, 16);
				}
				{
					jLabel6 = new JLabel();
					jPanel1.add(jLabel6);
					jLabel6.setText("$");
					jLabel6.setBounds(205, 74, 10, 16);
				}
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Modificar");
				jButton1.setBounds(279, 253, 87, 23);
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton1.actionPerformed, event="+evt);
						 
						if (!KmExcedente.getText().equalsIgnoreCase(String.valueOf(t.getKmexcedente())) || (!costotexto.getText().equalsIgnoreCase(String.valueOf(t.getCostoxdia())))){
							 //AdministradorPersistenciaTipo.getInstancia().update(Float.parseFloat(costotexto.getText()), Float.parseFloat(KmExcedente.getText()),(String) jComboBox1.getSelectedItem());
							Sistema.getSistema().ModificarTipo(Float.parseFloat(costotexto.getText()), Float.parseFloat(KmExcedente.getText()),(String) jComboBox1.getSelectedItem());
						}
							 frmMainFrame main = new frmMainFrame(true,null);
							 main.setLocationRelativeTo(null);
							 main.setVisible(true);							
								dispose();
						 
					}
				});
			}
			pack();
			this.setSize(400, 325);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
